<!--
 * @Author: Freude Xu
 * @Date: 2021-10-05 16:46:30
 * @LastEditors: Freude Xu
 * @LastEditTime: 2021-10-05 16:53:42
 * @Description: 
-->
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>删除事件</title>
    <style>
        div {
            width: 100px;
            height: 100px;
            background-color: pink;
        }
    </style>
</head>

<body>
    <div>1</div>
    <div>2</div>
    <div>3</div>
</body>
<script>
    var divs = document.querySelectorAll('div');
    divs[0].onclick = function() {
        alert('11');
        //1.传统方式解绑事件
        divs[0].onclick = null;
    }
    divs[1].addEventListener('click', fn);

    function fn() {
        alert('22');
        //2.移除事件
        divs[1].removeEventListener('click', fn);
    }
    //3.移除事件
    // divs[2].onclick=function (){
    //     alert('33');
    //与ie9的绑定事件一起用
    //     detachEvent();
    // }
</script>

</html>